#'
#' species frequency distribution for a given quadrat size, resulting a classic species abundance community matrix
#'
#' @param com a community object or a quadrat object returned by quadratize
#' @param nx,ny parameters used to quadraize the community object, see details in \code{\link{species_frequency}}
#'
#'
#' @examples 
#' data(BCI)
#' spfreq=species_frequency(BCI,5,5)
#' 
#' com=quadratize(BCI,5,5)
#' spfreq2=species_frequency(com)
#'
#' @export
species_frequency=function(com,nx,ny,...){
  if(!("quadrat" %in% class(com)))
    com=quadratize(com,nx,ny, ...)
  
  sptab=table(com$species,com$quadrati)
  spfreq=apply(sptab,1,function(x) sum(x!=0))
  #spfreq[match(names(spfreq),species_list(com))]
  return(spfreq)
}